package com.example.lin.ximalaya.utils;

import java.text.DecimalFormat;

public class NumberUtils {


    /**
     * 将 long 值,转换为 {x.x亿,或x.x万,等...}
     * @param number
     * @return
     */
    public static final String number2String(long number) {
        if (number > 100000000L) {
            return formatDouble(number / 100000000.0) + "亿";
        } else if (number > 10000L) {
            return formatDouble(number / 10000.0) + "万";
        } else {
            return String.valueOf(number);
        }
    }


    /**
     * 保留1位小数
     *
     * @param d
     * @return
     */
    public static String formatDouble(double d) {
        DecimalFormat df = new DecimalFormat("#.0");
        return df.format(d);
    }


}
